package com.fantastic.web.controller.app;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.AccountCoupons;
import com.fantastic.service.zjs.AccountCouponsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: rxx
 * @since: 2024/6/4 09:15
 * @description: 用户优惠券关联表请求控制器
 */
@RestController
@RequestMapping("/app")
public class AccountCouponsController {

    @Resource
    private AccountCouponsService accountCouponsService;

    /**
     * 查询单个用户下所有的优惠券关联信息
     *
     * @param accountId
     * @return
     */
    @GetMapping("/getAccountCoupons")
    public ResultData listAccountCouponsApp(Integer accountId) {
        return new ResultData(RespStatusInfo.OK, accountCouponsService.getAccountCoupons(accountId));
    }

    /**
     * 添加用户优惠券关联信息
     *
     * @param accountCoupons
     * @return
     */
    @PostMapping("/insertAccountCouponsApp")
    public ResultData insertAccountCouponsApp(AccountCoupons accountCoupons) {
        return new ResultData(RespStatusInfo.OK, accountCouponsService.insertAccountCoupons(accountCoupons));
    }

    /**
     * 账号通过积分兑换优惠券
     *
     * @param accountId        账号id
     * @param couponId         优惠卷id
     * @param integralExchange 所需要的积分
     * @return
     */
    @PostMapping("/creditsExchangeApp")
    public ResultData creditsExchangeApp(Integer accountId, Integer couponId, Integer integralExchange,
                                         Integer integralId, Integer integralSell) {
        return new ResultData(RespStatusInfo.OK, accountCouponsService.creditsExchange(accountId, couponId,
                integralExchange, integralId, integralSell));
    }

    /**
     * 删除用户优惠券关联信息
     *
     * @param accountId
     * @param couponId
     * @return
     */
    @PostMapping("/deleteAccountCouponsApp")
    public ResultData deleteAccountCouponsApp(Integer accountId, Integer couponId) {
        return new ResultData(RespStatusInfo.OK, accountCouponsService.deleteAccountCoupons(accountId, couponId));
    }

}
